home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / SAS-C / sc655pch / amiproc / READ.ME < prev    next >
Encoding:
Text File  |  1995-01-09  |  5.8 KB  |  123 lines

  1. AMIPROC Copyright (c) 1989-1995 Steve Krueger and Doug Walker, 
  2. Raleigh, NC, USA.  All Rights Reserved.
  3.  
  4. Send any correspondance to:
  5.  
  6.     walker@unx.sas.com
  7.     sassek@unx.sas.com
  8.  
  9. This distribution is freely redistributable provided that you do not 
  10. modify the contents of the files, and that all files are kept together.
  11. You may use this code freely in your commercial and noncommercial
  12. projects.  
  13.  
  14. The programs and documentation in this distribution are provided on an
  15. AS-IS basis only.  No warranty is expressed or implied, including the
  16. warranty of fitness for a particular purpose.  Use this code at your
  17. own risk.  By your use of this code, you agree that the authors will
  18. not be responsible for any consequences of its use.
  19.  
  20. AMIPROC: Spawn a new process with its own near data section.
  21. Requires the SAS/C® Development System Version 6.50 or higher 
  22. (Some features might work with Version 6.0).
  23.  
  24. SAS/C is a registered trademark of SAS Institute, Inc, Cary, NC, USA.
  25.  
  26. AMIPROC consists of a couple of small functions that will start a new
  27. process, initialize a near data section for it, and run the SAS/C
  28. autoinit and autoterm functions.  The autoinit/autoterm functions
  29. give you the ability to use virtually the entire SAS/C link library
  30. in your new process, as well as running C++ constructors and 
  31. destructors and user-written autoinit/autoterm functions.
  32.  
  33. ***HOW TO USE AMIPROC
  34.  
  35.    1. Include the file "amiproc.h" in your C source file.
  36.  
  37.    2. When you want to start your new process, call the function
  38.       AmiProc_Start():
  39.       
  40.          res = AmiProc_Start(func, userdata);
  41.          
  42.             struct AmiProcMsg *res;
  43.                The return value is a pointer to a private data structure.
  44.                You need to keep track of it and pass it to AmiProc_Wait()
  45.                when you're ready to exit.  Do not attempt to read the
  46.                contents of this data structure.  If res is NULL, the
  47.                attempt to create a new process failed.
  48.  
  49.             int (*func)(void *userdata);
  50.                This parameter is a pointer to a function in your code.
  51.                The function should return "int" and take a "void *"
  52.                as its parameter.  The parameter will be the data pointer
  53.                passed as AmiProc_Start's second parameter.
  54.  
  55.             void *userdata;
  56.                This parameter is a pointer to data that you supply.  It
  57.                will be passed to your function as its argument when the 
  58.                subprocess has been created.  This data must not be
  59.                reused or freed until after the subprocess exits!
  60.  
  61.    3. Sometime before your main program exits, call AmiProc_Wait(),
  62.       passing it the pointer returned by AmiProc_Start().  AmiProc_Wait()
  63.       will wait until the subprocess exits, free some resources, then
  64.       return the subprocess's return code to you.  Do not attempt to use
  65.       the AmiProcMsg pointer after this.
  66.  
  67.    4. Make sure your subprocess does not call exit(), __exit(), abort(),
  68.       _XCEXIT(), or any other function that would cause your program
  69.       to exit (EVEN INDIRECTLY!).  If it does, the program will attempt
  70.       to free some resources belonging to the parent, which will cause 
  71.       other resources not to be freed.  Always exit by a simple return()
  72.       from your entry point function.
  73.  
  74.    5. Make sure your program is linked with the SAS/C-supplied cres.o
  75.       startup, that it is compiled with the NOSTACKCHECK and NOSTACKEXT
  76.       options, and that CTRL-C checking has been disabled.  See below 
  77.       for more explanation.
  78.  
  79.    6. Link with the object file amiproc.o (provided).
  80.  
  81. ***WARNINGS/POSSIBLE PROBLEMS
  82.  
  83.    Remember that although you have your own NEAR data section in the
  84.    subprocess, FAR and CHIP data will still be shared with the parent
  85.    process.  Either reserve FAR and CHIP for read-only data or use 
  86.    semaphores to protect any read/write FAR or CHIP data. 
  87.  
  88.    String literals ("the ones in double quotes") count as external data,
  89.    too.  If you do not specify the STRSECT or STRMERGE options, they
  90.    will go whereever your external data goes.  Since you probably don't
  91.    modify string literals, STRSECT=CODE or STRSECT=FAR will save your
  92.    program some space in the near section.  STRMERGE will also save
  93.    some space.  Use these options if you have a lot of near data and 
  94.    need to make room, or if you want to minimize the amount of data that 
  95.    gets duplicated each time you create a new subprocess
  96.  
  97.    Make sure your program is compiled with NOSTACKCHECK and NOSTACKEXT.
  98.    (NOSTACKEXT is the default).  These options rely on the values of
  99.    certain external variables, which are not set up for the new 
  100.    subprocess.  (This could probably be made to work, but we haven't 
  101.    done it.  If you want to try, you'd need to duplicate the code in 
  102.    c.a that deals with setting the stack up.)
  103.  
  104.    Make sure that CTRL-C checking is disabled in your subprocess.
  105.    The easiest way to do this is to disable the __chkabort function.
  106.    See your SAS/C V6.50 User's Guide, page 220, for a description
  107.    of how to disable CTRL-C checking.  If you link with the SC
  108.    command, you can use the NOCHKABORT option described in the
  109.    User's Guide instead.
  110.  
  111.    Make sure your program is linked with the cres.o startup.  Programs
  112.    linked with cres.o have a read-only copy of their initialized near
  113.    data that these macros access.  Programs linked with c.o or cback.o
  114.    do not have this extra copy.  Even if these programs link correctly,
  115.    which may or may not be true, they won't work as expected since
  116.    external variables used by library functions will be initialized
  117.    incorrectly.  (For example, the malloc() memory pools in both 
  118.    processes will be pointing to the same memory blocks...)
  119.  
  120.    Remember that the __saveds keyword and the geta4() function do not 
  121.    work in code linked with cres.o.  This is described in your SAS/C
  122.    manual.
  123.